home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / mus / misc / NSM_inslines.lha / insertlines / insertlines.c < prev    next >
C/C++ Source or Header  |  1999-02-19  |  4KB  |  139 lines

  1. /*
  2.     Inserts or deletes <n> number of lines on all the tracks
  3.     at the current cursorline-position. Does allso
  4.     update the length of the block to <oldlength>+<n>
  5.     and update the highlightened lines to the new
  6.     positions.
  7.  
  8.     If you are just going to insert or delete one line, the
  9.     "RN_INSERTLINE" and "RN_DELETELINE" commands are about
  10.     just as fast as the plug-in. But with more lines to
  11.     delete/insert, the plug-ins gets exponential faster.
  12.  
  13.     Recommended shortcut: Shift-return.
  14.  
  15.     Made by Kjetil S. Matheussen.
  16.  
  17.     Updated: 19.2.99. Changes: Uses the new functions in
  18.     NSM; "sethighlightline" and "unsethighlightline", rewritten
  19.     the delete-rutine, and fixed a bug. The plug-in is now many
  20.     thousands times faster than previous versions.
  21.  
  22.     Updated: 8.1.99. Changes: Can delete lines too, and
  23.     Con-window allways opens at the octamed-screen.
  24.  
  25.     First version: 15.12.98.
  26.  
  27.     Link with /readstr.o and /octacontrol.o to compile. Needs
  28.     at least NSM V074.
  29.  
  30.     e-mail: kjetilma@ifi.uio.no
  31.  
  32.     Address:
  33.     Kjetil S. Matheussen
  34.     5423 Sogn Studentby
  35.     0858 Oslo
  36.     Norway
  37. */
  38.  
  39. #include <string.h>
  40. #include "/nsm.h"
  41. #include "/readstr.h"
  42.  
  43. void main(){
  44.     OCTABASE ob;
  45.     BLOCKBASE bb;
  46.  
  47.     UWORD numlines,numtracks,currline,track,page,numpages,highline;
  48.     int insertlines,line;
  49.  
  50.     char *dosbase,*filehandle;
  51.     char string[80];
  52.  
  53.     if((ob=getoctabase())==0) goto exit;            /* Allways include this line first in
  54.                                                                     your plug-ins. */
  55.  
  56.     dosbase=opendoslibrary();
  57.     filehandle=openoctacon(dosbase,350,60);
  58.  
  59.     bb=getcurrblockbase(ob);
  60.  
  61.     writestring(dosbase,filehandle,"(To delete lines, use a \"-\")\n\n",30);
  62.     writestring(dosbase,filehandle,"Number of lines to insert: ",27);
  63.     readstring(dosbase,filehandle,string,70);
  64.     numlines=getnumlines(bb);                            /* Has to be put here. */
  65.     sscanf(string,"%d",&insertlines);
  66.     if(insertlines+numlines<=0 || insertlines+numlines>3200) goto close;
  67.  
  68.     numtracks=getnumtracks(bb);
  69.     currline=getcurrline(ob);
  70.     numpages=getnumpages(bb)+1;
  71.  
  72.     if(insertlines>0){
  73.         sendrexxword("ED_SETBLOCKLINES LINES ",numlines+insertlines,"");
  74.         bb=getcurrblockbase(ob);        /* Have to update the bb-pointer, because we have
  75.                                                 changed the length of the block, and it has got a new base. */
  76.         numlines=numlines+insertlines;
  77.  
  78.         for(line=numlines;line>=currline+insertlines;line--){
  79.             for(track=0;track<numtracks;track++){
  80.                 setnote(bb,track,line,getnote(bb,track,line-insertlines));
  81.                 setinum(bb,track,line,getinum(bb,track,line-insertlines));
  82.                 for(page=1;page<=numpages;page++){
  83.                     setcmdnum(bb,track,line,page,getcmdnum(bb,track,line-insertlines,page));
  84.                     setcmdlvl(bb,track,line,page,getcmdlvl(bb,track,line-insertlines,page));
  85.                 }
  86.             }
  87.             highline=getlinehighlight(bb,line-insertlines);
  88.             if (highline!=getlinehighlight(bb,line))
  89.                 if (highline==1){
  90.                     setlinehighlight(bb,line);
  91.                 }else{
  92.                     unsetlinehighlight(bb,line);
  93.                 }
  94.         }
  95.  
  96.         for(line=currline;line<currline+insertlines;line++){
  97.             for(track=0;track<numtracks;track++){
  98.                 setnote(bb,track,line,0);
  99.                 setinum(bb,track,line,0);
  100.                 for(page=1;page<=numpages;page++){
  101.                     setcmdnum(bb,track,line,page,0);
  102.                     setcmdlvl(bb,track,line,page,0);
  103.                 }
  104.             }
  105.             if (getlinehighlight(bb,line)==1) unsetlinehighlight(bb,line);
  106.         }
  107.         updateeditor(ob);
  108.  
  109.  
  110.     }else{
  111.  
  112.         for(line=currline;line<numlines+insertlines;line++){
  113.             for(track=0;track<numtracks;track++){
  114.                 setnote(bb,track,line,getnote(bb,track,line-insertlines));
  115.                 setinum(bb,track,line,getinum(bb,track,line-insertlines));
  116.                 for(page=1;page<=numpages;page++){
  117.                     setcmdnum(bb,track,line,page,getcmdnum(bb,track,line-insertlines,page));
  118.                     setcmdlvl(bb,track,line,page,getcmdlvl(bb,track,line-insertlines,page));
  119.                 }
  120.             }
  121.             highline=getlinehighlight(bb,line-insertlines);
  122.             if (highline!=getlinehighlight(bb,line))
  123.                 if (highline==1){
  124.                     setlinehighlight(bb,line);
  125.                 }else{
  126.                     unsetlinehighlight(bb,line);
  127.                 }
  128.         }
  129.         sendrexxword("ED_SETBLOCKLINES LINES ",numlines+insertlines,"");
  130.     }
  131.  
  132.  
  133. close:
  134.     closefile(dosbase,filehandle);
  135.     closedoslibrary(dosbase);
  136.  
  137. exit:
  138. }
  139.